<?php
session_start();
/* SSL Management */
$useSSL = true;
include(dirname(__FILE__).'/../config/config.inc.php');
include(dirname(__FILE__).'/../init.php');

//CSS ans JS file calls
$js_files = array(
	_THEME_JS_DIR_.'tools/statesManagement.js',
	__PS_BASE_URI__.'js/jquery/jquery-typewatch.pack.js'
);
$errors = array();

if (Tools::isSubmit('SubmitLogin'))
{
	$passwd = trim(Tools::getValue('passwd'));
	$email  = trim(Tools::getValue('email'));
        
	if (empty($email))
		$errors[] = Tools::displayError('e-mail address is required');
	elseif (!Validate::isEmail($email))
		$errors[] = Tools::displayError('invalid e-mail address');
	elseif (empty($passwd))
		$errors[] = Tools::displayError('password is required');
	elseif (Tools::strlen($passwd) > 32)
		$errors[] = Tools::displayError('password is too long');
	elseif (!Validate::isPasswd($passwd))
		$errors[] = Tools::displayError('invalid password');
	else
	{
		$customer = new Customer();
		$authentication = $customer->getByEmail_ext(trim($email), trim($passwd));
//                echo 'www';
//                print_r($authentication);
                
             //   die;            
		/* Handle brute force attacks */
		sleep(1);
//                print_r($customer);
		if (!$authentication OR !$customer->id)
			$errors[] = Tools::displayError('authentication failed');
		else
		{
			$cookie->id_customer = intval($customer->id);
			$cookie->customer_lastname = $customer->lastname;
			$cookie->customer_firstname = $customer->firstname;
			$cookie->logged = 1;
			$cookie->passwd = $customer->passwd;
			$cookie->email  = $customer->email;
			if (Configuration::get('PS_CART_FOLLOWING') AND (empty($cookie->id_cart) OR Cart::getNbProducts($cookie->id_cart) == 0))
				$cookie->id_cart = intval(Cart::lastNoneOrderedCart(intval($customer->id)));
			Module::hookExec('authentication');
                        
//                        $_GET['step']  = 1;
                     
//                        header("Location: cart_ext.php?step=1");
//                        include('cart_ext.php');
//                        
//                        $_GET['ipa']   = $idProduct;
//                        
//                        include('order_ext.php');                        
                             
//                                     print_r($cookie);
//			if ($back = Tools::getValue('back'))
//				Tools::redirect($back);
//			Tools::redirect('my-account.php');
		}
	}
}

$smarty->assign('errors', $errors);
Tools::safePostVars();
//$smarty->display(_PS_THEME_DIR_.'authentication.tpl');
//include(dirname(__FILE__).'/../footer.php');
   echo '<iframe src="../../order.php?step=1" width="1200" height="600"> </iframe>';

?>
